.global _start

_start:
	ldr pc, =Reset_Handler
	ldr pc, =Undefined_Handler
	ldr pc, =SVC_Handler
	ldr pc, =PrefAbort_Handler
	ldr pc, =DataAbort_Handler
	ldr pc, =NotUsed_Handler
	ldr pc, =IRQ_Handler
	ldr pc, =FIQ_Handler

Reset_Handler:
	cpsid i		/* disable IRQ */

	/* close I,DCache and MMU
	 */
	mrc     p15, 0, r0, c1, c0, 0
    bic     r0,  r0, #(0x1 << 12)
    bic     r0,  r0, #(0x1 <<  2)
    bic     r0,  r0, #0x2
    bic     r0,  r0, #(0x1 << 11)
    bic     r0,  r0, #0x1
    mcr     p15, 0, r0, c1, c0, 0

	/*
	 * DDR range:0X80000000~0X9FFFFFFF 512MB
	 */

	/* set the SP pointer for FIQ mode*/
	mrs r0, cpsr
	bic r0, r0, #0x1f
	orr r0, r0, #0x11
	msr cpsr, r0
	ldr sp, =0x80800000

	/* set the SP pointer for IRQ mode*/
	mrs r0, cpsr
	bic r0, r0, #0x1f
	orr r0, r0, #0x12
	msr cpsr, r0
	ldr sp, =0x80600000

	/* set the SP pointer for SYS mode*/
	mrs r0, cpsr
	bic r0, r0, #0x1f
	orr r0, r0, #0x1f
	msr cpsr, r0
	ldr sp, =0x80400000

	/* set the SP pointer for SVC mode*/
	mrs r0, cpsr
	bic r0, r0, #0x1f
	orr r0, r0, #0x13
	msr cpsr, r0
	ldr sp, =0x80200000

	cpsie i				/* enable IRQ */

	b kernel_main

Undefined_Handler:
	ldr r0, =Undefined_Handler
	bx r0

SVC_Handler:
	ldr r0, =SVC_Handler
	bx r0

PrefAbort_Handler:
	ldr r0, =PrefAbort_Handler
	bx r0

DataAbort_Handler:
	ldr r0, =DataAbort_Handler
	bx r0

NotUsed_Handler:
	ldr r0, =NotUsed_Handler
	bx r0

IRQ_Handler:
	ldr r0, =IRQ_Handler
	bx r0

FIQ_Handler:
	ldr r0, =FIQ_Handler
	bx r0
